package com.zprmb.udzt.adapter;

import java.text.DecimalFormat;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zprmb.udzt.R;
import com.zprmb.udzt.bean.HongbaoBean;

public class Hongbao_Adapter2 extends BaseAdapter {
	private List<HongbaoBean> list;
	private Context context;
	private String title;
	DecimalFormat df = new DecimalFormat("###0.00"); 
	

	

	public Hongbao_Adapter2(List<HongbaoBean> list, Context context,
			String title) {
		super();
		this.list = list;
		this.context = context;
		this.title = title;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		Help h=null;
		if(convertView==null){
			h=new Help();
			convertView=LayoutInflater.from(context).inflate(R.layout.red_item2, null);
			h.tv_keyong=(TextView)convertView.findViewById(R.id.tv_keyong);
			h.tv_total_money=(TextView)convertView.findViewById(R.id.red_amount);
			h.tv_used_money=(TextView)convertView.findViewById(R.id.yiyong);
			h.tv_used_time=(TextView)convertView.findViewById(R.id.used_time);
			h.keyong=(TextView)convertView.findViewById(R.id.keyong);
			h.li_red=(LinearLayout)convertView.findViewById(R.id.li_red_back);
			
			convertView.setTag(h);
		}else{
			h=(Help) convertView.getTag();
		}

		h.tv_keyong.setText(df.format(Double.parseDouble(list.get(position).getAvailableAmount())));
		h.tv_total_money.setText(df.format(Double.parseDouble(list.get(position).getAmount())));
		h.tv_used_money.setText(df.format(Double.parseDouble(list.get(position).getUsedAmount())));
		
		h.keyong.setText("剩余面额");
		
		h.li_red.setBackgroundResource(R.drawable.hongbao_2);
		
		
		
		h.tv_used_time.setText("使用期限"+list.get(position).getStartDate()+"-"+list.get(position).getEndDate());
		
		return convertView;
	}
	private static class Help{
		private TextView tv_keyong,tv_total_money,tv_used_money,tv_used_time,tv_used_status,keyong;
		private LinearLayout li_red;
	}

}
